<template>
  <!-- 检验规则维护（按品号）-巡检 -->
  <p-modal
    :title="title"
    :width="width"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
    <p-spin :spinning="confirmLoading">
      <p-form :form="form">
        <p-row>
		  <p-col  :span="12">
			<p-form-item label="一级工序名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  class="ant-input " v-decorator="[ 'processOneName', validatorRules.processOneName]" placeholder="请输入一级工序名称"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="12">
			<p-form-item label="一级工序编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<f-popup
						contextPath="mes-craft"
						v-decorator="['processOneCode', validatorRules.processOneCode]"
						:trigger-change="true"
						org-fields="process_code,process_name,process_twocode,process_twoname"
						dest-fields="process_one_code,process_one_name,process_two_code,process_two_name"
						code="mes_route"
						:add="this.url.add"
						isMultiSelect="popup"
						@oNvisible="oNvisible"
						:listaip="this.listaip"
						:mainTableID="this.mainTableID"
						@callback="popupCallback"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="12">
			<p-form-item label="二级工序名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  class="ant-input " v-decorator="[ 'processTwoName', validatorRules.processTwoName]" placeholder="请输入二级工序名称"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="12">
			<p-form-item label="二级工序编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  class="ant-input " v-decorator="[ 'processTwoCode', validatorRules.processTwoCode]" placeholder="请输入二级工序编码"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="12">
			<p-form-item label="巡检(是否)" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<j-dict-select-tag  type="radio" v-decorator="['isFirstInspect', validatorRules.isFirstInspect]" :trigger-change="true" dictCode="ba_yn" placeholder="请选择巡检(是否)"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="12">
			<p-form-item label="巡检时间段" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'patrolDate', validatorRules.patrolDate]" placeholder="请输入巡检时间段"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="12">
			<p-form-item label="抽检方式" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<j-dict-select-tag  type="list" v-decorator="['samplingType', validatorRules.samplingType]" :trigger-change="true" dictCode="rc_inspect_method" placeholder="请选择抽检方式"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="12">
			<p-form-item label="抽样数量" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input-number   v-decorator="[ 'samplingNumber', validatorRules.samplingNumber]" placeholder="请输入抽样数量" style="width: 100%"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="12">
			<p-form-item label="id外建" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'mesQcInspectRuleBymcodeId', validatorRules.mesQcInspectRuleBymcodeId]" placeholder="请输入id外建"></p-input>
			</p-form-item>
		  </p-col>
        </p-row>


      </p-form>
    </p-spin>
  </p-modal>
</template>

<script>

  import { httpAction } from '@/api/manage'
  import { SubmitOnchangMixin } from '@/mixins/SubmitOnchangMixin'
  import pick from 'lodash.pick'
  import JDictSelectTag from "@/components/dict/JDictSelectTag"

  export default {
    name: "MesQcInspectRulePatrolModal",
	mixins: [SubmitOnchangMixin],
    components: {
      JDictSelectTag,
    },
    props:{
      mainId:{
        type:String,
        required:false,
        default:''
      },
      listaip: {
        type: String,
        default: ''
      },
    },
    watch: {
      mainId: {
        deep: true,
        handler (val) {
          this.mainTableID['mesQcInspectRuleBymcodeId'] = val
        }
      }
    },
    data () {
      return {
        form: this.$form.createForm(this),
        title: '操作',
        mainTableID: {},
        width: 1200,
        labelCol: {
          xs: { span: 24 },
          sm: { span: 8 },
        },
        visible: false,
        model: {},
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },

        confirmLoading: false,
        validatorRules:{
        processOneName: {rules: [{ required: false, message: '请输入一级工序名称!' }]},
        processOneCode: {rules: [{ required: false, message: '请输入一级工序编码!' }]},
        processTwoName: {rules: [{ required: false, message: '请输入二级工序名称!' }]},
        processTwoCode: {rules: [{ required: false, message: '请输入二级工序编码!' }]},
        isFirstInspect: {},
        patrolDate: {},
        samplingType: {},
        samplingNumber: {},
        mesQcInspectRuleBymcodeId: {},
        },
        url: {
          add: '/mes-quality/mesQcInspectRuleBymcode/addMesQcInspectRulePatrol',
          edit: '/mes-quality/mesQcInspectRuleBymcode/editMesQcInspectRulePatrol',
        }

      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'createBy','createTime','updateBy','updateTime','remark','timestamp','companyId','factoryId','clientId','substituteId','flag','processOneName','processOneCode','processOneId','processTwoName','processTwoCode','processTwoId','isFirstInspect','patrolDate','samplingType','samplingNumber','mesQcInspectRuleBymcodeId'))
        })
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
		handleOk () {
			const that = this;
			// 触发表单验证
			this.form.validateFields((err, values) => {
			  if (!err) {
				  that.confirmLoading = true;
				  let httpurl = '';
				  let method = '';
				  let formData = Object.assign(this.model, values);
				  this.formData = Object.assign(this.model, values);
                  formData['mesQcInspectRuleBymcodeId'] = this.mainId
                  this.formData['mesQcInspectRuleBymcodeId'] = this.mainId
				  //新增触发
				  if(!this.model.id){
					httpurl+=this.url.add;
					method = 'post';
					if(this.EnhanceJS.afterAdd){
					  //新增之前
					  let Obj = eval(this.EnhanceJS.afterAdd)
					  new Obj(this)
					}else{
					  console.log("表单提交数据",formData)
					  that.modalFrom(httpurl,formData,method)
					}
				  }else{
					//编辑触发
					httpurl+=this.url.edit;
					method = 'put';
					if(this.EnhanceJS.afterEdit){
					 //编辑之前
					  let Obj = eval(this.EnhanceJS.afterEdit)
					  new Obj(this)
					}else{
					  console.log("表单提交数据",formData)
					  that.modalFrom(httpurl,formData,method)
					}
				  }
			  }

			})
		},
      handleCancel () {
        this.close()
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'createBy','createTime','updateBy','updateTime','remark','timestamp','companyId','factoryId','clientId','substituteId','flag','processOneName','processOneCode','processOneId','processTwoName','processTwoCode','processTwoId','isFirstInspect','patrolDate','samplingType','samplingNumber','mesQcInspectRuleBymcodeId'))
      },


    }
  }
</script>
